

#include <stdint.h>


/*
    value => water
    10 - 97
    250 - 2
    max 97%
*/

static uint8_t water_oil_to_water(uint16_t val)
{
    if( val > 2500 )
    {
        return 97;
    }
    else if(val > 2300 ) //81-97
    {
        return (val - 2300) * (97 - 80) / (2500 - 2300) + 80;
    }
    else if(val > 1900 ) // 50 - 80
    {
        return (val - 1900) * (80 - 50) / (2300 - 1900) + 50;
    }
    else if(val > 700 ) // 30 - 50
    {
        return (val - 700) * (50 - 30) / (1900 - 700) + 30;
    }    
    else if( val > 290 ) // 15 - 30
    {
        return (val - 290) * (30 - 15) / (700 - 290) + 15;
    }
    else if(val > 255 ) // 10-15
    {
        return (val - 255) * (15 - 10) / (290 - 255) + 10;
    }
    else
    {
        return 10; 
    }
}


/* water => oil 
   10% => 20%
   10%-35% => 20%-63%
   35%-60% => 20%
*/

static uint8_t water_oil_to_oil(uint8_t percent)
{
    if( percent > 60 )
    {
        return 20;
    }
    else if( percent > 34 )
    {
        return (percent - 35) * (33-17) / (60 - 35 ) + 17;
    }
    else if( percent > 9 )
    {
        return (percent - 10) * (63 - 20 ) / (35 - 10 ) + 10;
    }
    else 
    {
        return 0xff; // invalid data 
    }
}

// water percent to skin level 
static uint8_t water_oil_to_skin_level(uint8_t percent)
{
    if (percent > 50)
    {
        return 97;
    }
    return (percent - 10) * (97 - 30) / (97 - 50) + 30;
}
